/**
 * 
 */
package com.liusoft.android.fmagic;

/**
 * 游戏状态机
 *                  PAUSE
 *                    ^
 *                    |
 *     READY ----> RUNNING ----> FINISH
 *       |                           |      
 *       |---------------------------|
 * 
 * 
 * @author Winter Lau
 */
public class GameState {

    private final static byte MODE_READY 	= 1; //游戏准备就绪
    private final static byte MODE_RUNNING 	= 2; //游戏进行中
    private final static byte MODE_PAUSE 	= 3; //游戏被暂停
    
    private byte mCurrentMode;	//当前游戏状态
    
    public GameState() {
    	this.mCurrentMode = MODE_READY;
    }
    
    public final static GameState Restore() {
    	GameState game = new GameState();
    	game.mCurrentMode = MODE_PAUSE;
    	return game;
    }
    
    public boolean IsRunning() {
    	return this.mCurrentMode == MODE_RUNNING;
    }
    
    public boolean IsReady() {
    	return this.mCurrentMode == MODE_READY;
    }
    
    public boolean IsPause() {
    	return this.mCurrentMode == MODE_PAUSE;
    }
    
    /**
     * 开始
     * @return
     */
    public boolean Begin() {
    	if(this.mCurrentMode==MODE_READY||this.mCurrentMode==MODE_PAUSE){
    		this.mCurrentMode = MODE_RUNNING;
    		return true;
    	}
    	return false;
    }
    
    /**
     * 暂停
     * @return
     */
    public boolean Pause(){
    	if(this.mCurrentMode == MODE_RUNNING){
    		this.mCurrentMode = MODE_PAUSE;
    		return true;
    	}
    	return false;
    }
    
    /**
     * 结束
     * @return
     */
    public boolean Finish() {
    	if(this.mCurrentMode == MODE_RUNNING){
    		this.mCurrentMode = MODE_READY;
    		return true;
    	}
    	return false;
    }
    
    /**
     * 重置
     * @return
     */
    public boolean Reset() {
    	this.mCurrentMode = MODE_READY;
    	return true;
    }
}
